<template>
	<view>
		<u-navbar back-text="返回" :title="title"></u-navbar>
		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs-swiper activeColor="#2979ff" ref="tabs" :list="list" :current="current" 
					:offset="[5,5]"  @change="change" :is-scroll="false" swiperWidth="750"></u-tabs-swiper>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<view class="page-box">
							<view class="order" v-for="(res, index) in orderList[0]" :key="res.id">
								<view class="top">
									<view class="left">
										<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
										<view class="store">{{ res.store }}</view>
									</view>
									<view v-if="current === 2"
										:class="res.deal === '预约成功' ? 'right-success' : 'right-fail'">{{ res.deal }}</view>
								</view>
								<view class="item" v-for="(item, index) in res.goodsList" :key="index">
									<view class="left"><image :src="item.goodsUrl" mode="aspectFill"></image></view>
									<view class="content">
										<view class="title">{{ item.title }}</view>
										<view class="deliveryTime">{{ item.deliveryTime }}</view>
										<view class="tel">{{ item.tel }}</view>
									</view>
									<view class="right">
										<view class="type">￥{{ item.price }}</view>
									</view>
								</view>
								<view class="bottom">
									<view class="exchange btn" v-if="current === 0 || current === 1">
										取消{{ current === 1 ? '排队' : '预约'}}
									</view>
									<view class="evaluate btn" v-if="current === 2 && res.deal === '预约成功'" @click="show = true">评价</view>
									<view class="exchange btn" v-if="current === 2 && res.deal === '预约失败'" @click="goToTab(`/pages/work/index`)">重新预约</view>
								</view>
							</view>
							<u-loadmore :status="loadStatus[0]" bgColor="#f2f2f2"></u-loadmore>
						</view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;">
						<view class="page-box">
							<view>
								<view class="centre">
									<image src="https://cdn.uviewui.com/uview/template/taobao-order.png" mode=""></image>
									<view class="explain">
										您还没有相关的预约
										<view class="tips">可以去看看有那些想预约的</view>
									</view>
									<view class="btn">随便逛逛</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
			<u-modal v-model="show" title="评分" show-cancel-button>
				<view class="slot-content">
					<u-form :model="form" ref="uForm" label-width="130">
						<u-form-item label="服务态度">
							<u-rate :count="count" :colors="['#ffc454']" v-model="form.attitude" size="42"></u-rate>
						</u-form-item>
						<u-form-item label="服务时长">
							<u-rate :count="count" :colors="['#ffc454']" v-model="form.duration" size="42"></u-rate>
						</u-form-item>
						<u-form-item label="收费合理">
							<u-rate :count="count" :colors="['#ffc454']" v-model="form.charge" size="42"></u-rate>
						</u-form-item>
						<u-form-item label="意见反馈">
							<u-input v-model="form.textVal" type="textarea" :border="true"/>
						</u-form-item>
					</u-form>
				</view>
			</u-modal>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			show: false,
			count: 5,
			form: {
				attitude: 0,
				duration: 0,
				charge: 0,
				textVal: '',
			},
			title: '',
			orderList: [[], [], [], []],
			dataList: [
				{
					id: 2,
					store: '松山湖美发室',
					deal: '预约成功',
					goodsList: [
						{
							goodsUrl: '../../static/images/appointment/nav1.webp',
							title: '一线员工晚间烫染排队',
							type: '洗剪吹',
							deliveryTime: '2024-03-01 14:30-15:00',
							price: '128.05',
							tel: '13888888888',
							number: 1
						}
					]
				},
				{
					id: 3,
					store: '东城美发室',
					deal: '预约失败',
					goodsList: [
						{
							goodsUrl: '../../static/images/appointment/nav2.webp',
							title: '常规预约/排队',
							type: '洗剪吹',
							deliveryTime: '2024-03-01 14:30-15:00',
							price: '199',
							tel: '13888888888',
							number: 1
						}
					]
				},
				{
					id: 4,
					store: '松山湖美发室',
					deal: '预约失败',
					goodsList: [
						{
							goodsUrl: '../../static/images/appointment/nav1.webp',
							title: '一线员工晚间烫染排队',
							type: '洗剪吹',
							tel: '13888888888',
							deliveryTime: '2024-03-01 14:30-15:00',
							price: '154',
							number: 1
						}
					]
				},
				{
					id: 5,
					store: '松山湖美发室',
					deal: '预约成功',
					goodsList: [
						{
							goodsUrl: '../../static/images/appointment/nav2.webp',
							title: '常规预约/排队',
							type: '洗剪吹',
							tel: '13888888888',
							deliveryTime: '2024-03-01 14:30-15:00',
							price: '45',
							number: 1
						}
					]
				}
			],
			list: [
				{
					id: 0,
					name: '当前预约'
				},
				{
					id: 1,
					name: '当前排队'
				},
				{
					id: 2,
					name: '历史预约记录'
				}
			],
			current: 0,
			swiperCurrent: 0,
			tabsHeight: 0,
			dx: 0,
			loadStatus: ['loadmore','loadmore','loadmore','loadmore'],
		};
	},
	onLoad() {
		this.init()
		this.getOrderList(0);
		// this.getOrderList(1);
		// this.getOrderList(3);
	},
	computed: {
		// 价格小数
		priceDecimal() {
			return val => {
				if (val !== parseInt(val)) return val.slice(-2);
				else return '00';
			};
		},
		// 价格整数
		priceInt() {
			return val => {
				if (val !== parseInt(val)) return val.split('.')[0];
				else return val;
			};
		}
	},
	methods: {
		/**
		 * 初始化
		 */
		init() {
			this.title = this.$route.query.title
			let temp = this.list.find((item,index) => item.name === this.title)
			this.current = temp.id
		},
		/**
		 * 导航页面跳转
		 */
		goToTab(url) {
			uni.switchTab({
				url: url
			})
		},
		reachBottom() {
			// 此tab为空数据
			if(this.current != 2) {
				this.loadStatus.splice(this.current,1,"loading")
				setTimeout(() => {
					this.getOrderList(this.current);
				}, 1200);
			}
		},
		// 页面数据
		getOrderList(idx) {
			for(let i = 0; i < 5; i++) {
				let index = this.$u.random(0, this.dataList.length - 1);
				let data = JSON.parse(JSON.stringify(this.dataList[index]));
				data.id = this.$u.guid();
				this.orderList[idx].push(data);
			}
			this.loadStatus.splice(this.current,1,"loadmore")
		},
		// 总价
		totalPrice(item) {
			let price = 0;
			item.map(val => {
				price += parseFloat(val.price);
			});
			return price.toFixed(2);
		},
		// 总件数
		totalNum(item) {
			let num = 0;
			item.map(val => {
				num += val.number;
			});
			return num;
		},
		// tab栏切换
		change(index) {
			this.current = index;
			this.title = this.list[index].name;
			this.getOrderList(0);
		},
		transition({ detail: { dx } }) {
			this.$refs.tabs.setDx(dx);
		},
		animationfinish({ detail: { current } }) {
			this.$refs.tabs.setFinishCurrent(current);
			this.swiperCurrent = current;
			this.current = current;
		}
	}
};
</script>

<style>
/* #ifndef H5 */
page {
	height: 100%;
	background-color: #f2f2f2;
}
/* #endif */
</style>

<style lang="scss" scoped>
.u-form {
	margin: 20rpx 40rpx;
}
.u-border-bottom:after {
	border: none;
}
.u-form-item {
	padding: 0;
}
.order {
	width: 710rpx;
	background-color: #ffffff;
	margin: 20rpx auto;
	border-radius: 20rpx;
	box-sizing: border-box;
	padding: 20rpx;
	font-size: 28rpx;
	.top {
		display: flex;
		justify-content: space-between;
		.left {
			display: flex;
			align-items: center;
			.store {
				margin: 0 10rpx;
				font-size: 32rpx;
				font-weight: bold;
			}
		}
		.right-fail {
			color: $u-tips-color;
		}
		.right-success {
			color: $u-type-warning-dark;
		}
	}
	.item {
		display: flex;
		margin: 20rpx 0 0;
		.left {
			margin-right: 20rpx;
			image {
				width: 200rpx;
				height: 200rpx;
				border-radius: 10rpx;
			}
		}
		.content {
			.title {
				font-size: 28rpx;
				line-height: 50rpx;
			}
			.deliveryTime {
				font-size: 24rpx;
				color: $u-tips-color;
				line-height: 40rpx;
			}
			.tel {
				margin: 10rpx 0;
				font-size: 24rpx;
				line-height: 40rpx;
				color: $u-tips-color;
			}
		}
		.right {
			margin-left: 10rpx;
			padding-top: 5rpx;
			text-align: right;
			position: absolute;
			right: 45rpx;
			.type {
				font-size: 24rpx;
				color: $u-type-info;
				line-height: 40rpx;
			}
			.decimal {
				font-size: 24rpx;
				margin-top: 4rpx;
			}
			.number {
				color: $u-tips-color;
				font-size: 24rpx;
			}
		}
	}
	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;
		.total-price {
			font-size: 32rpx;
		}
	}
	.bottom {
		padding: 0 10rpx;
		justify-content: space-between;
		align-items: center;
		position: relative;
		top: -50rpx;
		.btn {
			display: inline-block;
			margin-left: 10rpx;
			float: right;
			line-height: 52rpx;
			width: 160rpx;
			border-radius: 26rpx;
			border: 2rpx solid $u-border-color;
			font-size: 26rpx;
			text-align: center;
			color: $u-type-info-dark;
		}
		.evaluate {
			color: $u-type-primary;
			border-color: $u-type-primary;
		}
	}
}
.centre {
	text-align: center;
	margin: 200rpx auto;
	font-size: 32rpx;
	image {
		width: 164rpx;
		height: 164rpx;
		border-radius: 50%;
		margin: 0 auto;
		margin-bottom: 20rpx;
	}
	.tips {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}
	.btn {
		margin: 80rpx auto;
		width: 200rpx;
		border-radius: 32rpx;
		line-height: 64rpx;
		color: #ffffff;
		font-size: 26rpx;
		background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
	}
}
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--window-top));
	width: 100%;
}
.swiper-box {
	flex: 1;
}
.swiper-item {
	height: 100%;
}
::v-deep .u-tabs-item {
	color: $u-type-primary;
}
</style>
